package com.atguigu.yygh.hosp.service.impl;

import com.atguigu.yygh.common.R;
import com.atguigu.yygh.hosp.mapper.HospitalSetMapper;
import com.atguigu.yygh.hosp.service.HospitalSetService;
import com.atguigu.yygh.model.hosp.HospitalSet;
import com.atguigu.yygh.vo.hosp.HospitalSetQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {
    @Override
    public R pageList(Page<HospitalSet> pageParam, HospitalSetQueryVo hospitalSetQueryVo) {
        QueryWrapper<HospitalSet> wrapper=new QueryWrapper<>();
        if (hospitalSetQueryVo!=null){
            String hoscode = hospitalSetQueryVo.getHoscode();
            String hosname = hospitalSetQueryVo.getHosname();
            if (!StringUtils.isEmpty(hoscode)){
                wrapper.eq("hoscode",hoscode);
            }
            if (!StringUtils.isEmpty(hosname)){
                wrapper.like("hosname",hosname);
            }
            baseMapper.selectPage(pageParam,wrapper);
        }else {
            baseMapper.selectPage(pageParam,wrapper);
        }
        long total = pageParam.getTotal();
        List<HospitalSet> records = pageParam.getRecords();
        return R.ok().data("total",total).data("rows",records);
    }
}
